package com.asha.md360player4android.vr.plugins;

import com.asha.vrlib.MD360Director;
import com.asha.vrlib.model.MDMainPluginBuilder;
import com.asha.vrlib.objects.MDAbsObject3D;
import com.asha.vrlib.plugins.MDPanoramaPlugin;

import static com.asha.vrlib.common.GLUtil.glCheck;

/**
 * Created by android on 8/15/17.
 */

public class MultiPartPanoramaPlugin extends MDPanoramaPlugin {
    public MultiPartPanoramaPlugin(MDMainPluginBuilder builder) {
        super(builder);
    }

    @Override
    public void renderer(int index, int width, int height, MD360Director director) {


        MDAbsObject3D object3D = mProjectionModeManager.getObject3D();
        // check obj3d
        if (object3D == null) return;

        director.updateViewport(width, height);

        // Set our per-vertex lighting program.
        mProgram.use();
        glCheck("MDPanoramaPlugin mProgram use");

        mTexture.texture(mProgram);

        for (int i = 0; i < 4; i++) {
            // Update Projection

            object3D.uploadVerticesBufferIfNeed(mProgram, index);

            object3D.uploadTexCoordinateBufferIfNeed(mProgram, index);

            // Pass in the combined matrix.
            // model view projection matrix.
            director.beforeShot();
            director.shot(mProgram, getModelPosition());
            object3D.draw();
        }

    }

}
